package tools
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Matrix;
	
	import org.flixel.FlxSprite;

	public class MyFlxSprite extends FlxSprite
	{
		public function MyFlxSprite(X:uint = 0, Y:uint = 0, SimpleGraphic:Class = null)
		{
			super(X, Y, SimpleGraphic)
		}
		
		
		/**
		 * Load an image from an dynamic BitmapData.
		 * 
		 * @param	Graphic		The image you want to use.
		 * @param	Animated	Whether the Graphic parameter is a single sprite or a row of sprites.
		 * @param	Reverse		Whether you need this class to generate horizontally flipped versions of the animation frames.
		 * @param	Width		Optional, specify the width of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets).
		 * @param	Height		Optional, specify the height of your sprite (helps FlxSprite figure out what to do with non-square sprites or sprite sheets).
		 * @param	Unique		Optional, whether the graphic should be a unique instance in the graphics cache.  Default is false.
		 * 
		 * @return	This FlxSprite instance (nice for chaining stuff together, if you're into that).
		 */
		public function loadGraphicWithBitmap(bitmap:BitmapData, Animated:Boolean=false, Reverse:Boolean=false, Width:uint=0, Height:uint=0, Unique:Boolean=false):FlxSprite {
			_bakedRotation = 0;
			_pixels = bitmap;
			
			if (Reverse) {
				var newPixels:BitmapData = new BitmapData(pixels.width << 1, pixels.height, true, 0x00000000);
				newPixels.draw(pixels);
				var mtx:Matrix = new Matrix();
				mtx.scale(-1, 1);
				mtx.translate(newPixels.width, 0);
				newPixels.draw(pixels, mtx);
				pixels = newPixels;
				_flipped = _pixels.width >> 1;
			} else
				_flipped = 0;
			
			if (Width == 0) {
				if (Animated)
					Width = _pixels.height;
				else if (_flipped > 0)
					Width = _pixels.width * 0.5;
				else
					Width = _pixels.width;
			}
			
			width = frameWidth = Width;
			
			if (Height == 0) {
				if (Animated)
					Height = width;
				else
					Height = _pixels.height;
			}
			height = frameHeight = Height;
			resetHelpers();
			return this;
		}
		
		
		
	}
}